import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import detail from './modules/detail'

Vue.use(Vuex)

const myPlugin = store => {
  store.subscribe((mutation, state) => {
    console.log(mutation)
    if (mutation.type.startsWith('user/')) {
      window.localStorage.setItem('user', JSON.stringify(state.user))
    } else {
      console.log('1')
    }
  })
}

export default function createStore(){
  return new Vuex.Store({
    strict: process.env.NODE_ENV !== 'production',
    modules: {
      user,
      detail
    },
    plugins: [
      myPlugin
    ]
  })
}
